﻿using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace PasteLoggerBoard.EntityFrameworkCore.Migrations
{
    public partial class init_data_base : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "PTDayReport",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DataDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    DataTime = table.Column<long>(type: "bigint", nullable: false),
                    NumInfo = table.Column<int>(type: "integer", nullable: false),
                    NumWarning = table.Column<int>(type: "integer", nullable: false),
                    NumError = table.Column<int>(type: "integer", nullable: false),
                    NumException = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTDayReport", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTLogError",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DateLog = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    TimeLong = table.Column<long>(type: "bigint", nullable: false),
                    Level = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    MessageTemplate = table.Column<string>(type: "text", nullable: true),
                    Properties = table.Column<JsonElement>(type: "jsonb", nullable: false),
                    Exception = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTLogError", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTLogException",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DateLog = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    TimeLong = table.Column<long>(type: "bigint", nullable: false),
                    Level = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    MessageTemplate = table.Column<string>(type: "text", nullable: true),
                    Properties = table.Column<JsonElement>(type: "jsonb", nullable: false),
                    Exception = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTLogException", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTLogInfo",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DateLog = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    TimeLong = table.Column<long>(type: "bigint", nullable: false),
                    Level = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    MessageTemplate = table.Column<string>(type: "text", nullable: true),
                    Properties = table.Column<JsonElement>(type: "jsonb", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTLogInfo", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTLogWarning",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DateLog = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    TimeLong = table.Column<long>(type: "bigint", nullable: false),
                    Level = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    MessageTemplate = table.Column<string>(type: "text", nullable: true),
                    Properties = table.Column<JsonElement>(type: "jsonb", nullable: false),
                    UserAgent = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
                    Path = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
                    ClientIP = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
                    ConnectionId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    RequestId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTLogWarning", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTWebHooker",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    Url = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
                    WebType = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: true),
                    IsEnable = table.Column<bool>(type: "boolean", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTWebHooker", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTWebHookLink",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    WebHookerId = table.Column<int>(type: "integer", nullable: false),
                    Level = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    IsEnable = table.Column<bool>(type: "boolean", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTWebHookLink", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTWebHookLog",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    WebHookerId = table.Column<int>(type: "integer", nullable: false),
                    CreateDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    Success = table.Column<bool>(type: "boolean", nullable: false),
                    Body = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTWebHookLog", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_PTDayReport_DataDate",
                table: "PTDayReport",
                column: "DataDate");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "PTDayReport");

            migrationBuilder.DropTable(
                name: "PTLogError");

            migrationBuilder.DropTable(
                name: "PTLogException");

            migrationBuilder.DropTable(
                name: "PTLogInfo");

            migrationBuilder.DropTable(
                name: "PTLogWarning");

            migrationBuilder.DropTable(
                name: "PTWebHooker");

            migrationBuilder.DropTable(
                name: "PTWebHookLink");

            migrationBuilder.DropTable(
                name: "PTWebHookLog");
        }
    }
}
